<style>
.verticalText
{
/*browser basati Chrome, Safari...*/
-webkit-transform: rotate(-90deg);
/*Firefox*/
-moz-transform: rotate(-90deg);
/*Internet Explorer*/
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
};

</style>


 <?php

/* array sort helper function */
function randomSort($a, $b)
{
    return rand(-1, 1);
}
	
class PTagCloud
{
	var $m_arTags = array();
	
	//custom parameters
	var $m_displayedElementsCount;
	var $m_backgroundColor;
	var $m_width;
	var $m_arColors;

	
	function cloud_Construct($DisplayWordCount)
	{
	    $this->m_displayedElementsCount = $DisplayWordCount;
	   
	    $this->m_backgroundColor = "#FFFFFF";
	    $this->m_arColors[0] = "#FF00FF";
	    $this->m_arColors[1] = "#461B7E";
	    $this->m_arColors[2] = "#57FEFF";
	    $this->m_arColors[3] = "#819922";
	    $this->m_arColors[4] = "#FFFF00";
	    $this->m_arColors[5] = "#8A4117";
	    $this->m_arColors[6] = "#C11B17";
	    $this->m_arColors[7] = "#FAF8CC";
	    $this->m_arColors[8] = "#229938";
	    $this->m_arColors[9] = "#419922";
	    
	}
	 
	 
	function PTagCloud($DisplayWordCount)
	{
		$this->cloud_Construct($DisplayWordCount);
	}
	
	
	function setWidth($width)
	{
	    $this->m_width = $width;
	}
	
	function setBackgroundColor($backgroundColor)
	{
	    $this->m_backgroundColor = $backgroundColor;
	}
	
	function setTextColors($arColors)
	{
	    $this->m_arColors = $arColors;
	}
	 
	/* word replace helper */
    function str_replace_word($needle, $replacement, $haystack)
    {
        $pattern = "/\b$needle\b/i";
        $haystack = preg_replace($pattern, $replacement, $haystack);
        return $haystack;
    }

    function keywords_extract($text)
    {
        //$text = strtolower($text);
        $text = strip_tags($text);
      
	    $commonWords = "'tis,'twas,a,able,about,across,after,ain't,all,almost,also,am,among,an,and,any,are,aren't," .
            "as,at,be,because,been,but,by,can,can't,cannot,could,could've,couldn't,dear,did,didn't,do,does,doesn't," .
            "don't,either,else,ever,every,for,from,get,got,had,has,hasn't,have,he,he'd,he'll,he's,her,hers,him,his," .
            "how,how'd,how'll,how's,however,i,i'd,i'll,i'm,i've,if,in,into,is,isn't,it,it's,its,just,least,let,like," .
            "likely,may,me,might,might've,mightn't,most,must,must've,mustn't,my,neither,no,nor,not,o'clock,of,off," .
            "often,on,only,or,other,our,own,rather,said,say,says,shan't,she,she'd,she'll,she's,should,should've," .
            "shouldn't,since,so,some,than,that,that'll,that's,the,their,them,then,there,there's,these,they,they'd," .
            "they'll,they're,they've,this,tis,to,too,twas,us,wants,was,wasn't,we,we'd,we'll,we're,were,weren't,what," .
            "what'd,what's,when,when,when'd,when'll,when's,where,where'd,where'll,where's,which,while,who,who'd," .
            "who'll,who's,whom,why,why'd,why'll,why's,will,with,won't,would,would've,wouldn't,yet,you,you'd,you'll," .
            "you're,you've,your".
			"dont,doesnt";
			
        $commonWords = strtolower($commonWords);
		
		/*
		
		// Usability of explode function.
		$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
		$pieces = explode(" ", $pizza);
		echo $pieces[0]; // piece1
		echo $pieces[1]; // piece2

		*/
        $commonWords = explode(",", $commonWords);
        
		// Delete common words from the text.
		// Sicne, we are replacing the common words with ""
		foreach($commonWords as $commonWord)
        {
            $text = $this->str_replace_word($commonWord, "", $text);  
        }

         $text = preg_replace('/[^a-zA-Z0-9\s]|\n|\r/',' ',$text);
            
        /* remove extra spaces created */
        $text = preg_replace('/ +/',' ',$text);
      
        $text = trim($text);
        $words = explode(" ", $text);
        foreach ($words as $value) 
        {
            $temp = trim($value);
            if (is_numeric($temp))
                continue;
            $keywords[] = trim($temp);
        }
    
        return $keywords;
    }
  
    function addTagsFromText($SeedText)
    {
        $words = $this->keywords_extract($SeedText);
		foreach ($words as $key => $value)
		{
			$this->addTag($value);
			
		}
    }
	
	function addTag($tag, $useCount = 1)
	{
		//$tag = strtolower($tag); 
		if (array_key_exists($tag, $this->m_arTags))
			$this->m_arTags[$tag] += $useCount;
		else
			$this->m_arTags[$tag] = $useCount;
	}
	 
	function gradeFrequency($frequency)
	{
	    $grade = 0;
		if ($frequency >= 45)
			$grade = 9;
		else if ($frequency >= 40)
			$grade = 8;
		else if ($frequency >= 35)
			$grade = 7;
		else if ($frequency >= 30)
			$grade = 6;
		else if ($frequency >= 25)
			$grade = 5;
		else if ($frequency >= 20)
			$grade = 4;
		else if ($frequency >= 15)
			$grade = 3;
		else if ($frequency >= 10)
			$grade = 2;
		else if ($frequency >= 5)
			$grade = 1;
		 
		return $grade;
	}
	 
	function emitCloud($bHTML = true)
	{
	    arsort($this->m_arTags);
	    $arTopTags = array_slice($this->m_arTags, 0, $this->m_displayedElementsCount);
	    
	    /* randomize the order of elements */
		uasort($arTopTags, 'randomSort');
		
		$this->maxCount = max($this->m_arTags);	
		echo "check check".$this->maxCount."<br>";

		if (is_array($this->m_arTags))
		{
			if ($bHTML) 
			{
				$result ="<table width=".$this->m_width."> "; 
				
			}
            else
			{			    
                $result = array();
			}
			//echo print_r($arTopTags,true).'<br/>';	
			//echo $arTopTags['going'].'<br/>';		
			//echo count($arTopTags).'<br/>';			
			$tag= array_keys($arTopTags);
			for ($i=0; $i < count($arTopTags) ; $i++)
			{

				$grade = $this->gradeFrequency(($arTopTags[$tag[$i]] * 100) / $this->maxCount);
				echo $arTopTags[$tag[$i]].".";
				if ($bHTML)
				{
		
					if(($i % 7)== 0)
					{
						$result .= "<tr>";	
					}
					
					$result .= ("<td width=".(0.6)*$grade."><span class=\"verticalText\" style=\"color:".$this->m_arColors[$grade].
								"; letter-spacing:3px;".
					    		"padding:3px; font-family:Harrington; font-weight:1500;font-size:".
								(0.6*$grade) . 
								"em\">".
								$tag[$i].
								"</span></td>");
								
					if(($i % 7)== 6)	
						$result .= "</tr>";		
				}
				else
				{
				    $result[$tag] = $grade;
				}
			}
			$result.="</table>";
			return $result;
		}
	}
}

?>


<?php
    $text_content = "This can be your post or mine." .
        "Rccardo When are you going to italy? " .
        "I dont know who is going where. I just dont know anything" .
        "But this is inetersting, this is cloud cloud cloud cloud cloud cloud cloud cloud" .
        "I think, Adrian is here. He is not going anywhere, Busy people. Good peeple, Bad people lazy peopla brilliant people, its good good good good" . 
		"Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello". 
		"The could be very general very general, very very very general too general, way to general, Huaaa, This is generelest general text". 
		"they're good people they're bad people, they're every kind of people, they're they're they're they're they're they're they're they're they're they're they're they're they're they're they're".
		"I like to drink coke, you like coke. i said coke u know coke omg u dont know coke, its coke coke coke coke"."see see see see see see see see see see see see see see see see see see see see see see see see see see see";


    $cloud = new PTagCloud(35);
    $cloud -> addTagsFromText($text_content); 
    $cloud -> setWidth("1000px");
    echo $cloud -> emitCloud();
	
?>     

